package 冒泡排序;

public class Test {
    public static void main(String[] args) {
        //从小到大
        MinToMax();
        //从大到小
        MaxToMin();
    }

    private static void MaxToMin() {
        int a[] = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,9};
        int temp;
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j]<a[j+1]){
                    temp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = temp;
                }
            }
        }

        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }

    private static void MinToMax() {
        int a[] = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,9};
        int temp;
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                if (a[j]>a[j+1]){
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }

        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }
}
